import ROBO_AVATAR from '@/assets/image/avatar_robo.png';
import FASONG from '@/assets/image/fasong.png';
import AvatarDef from '@/components/RightContent/AvatarDropdown';
import { useModel } from '@umijs/max';

import { message } from 'antd';
import React, { useEffect } from 'react';
import { history } from 'umi';
import './index.less';
const Main: React.FC = () => {
  const { initialState } = useModel('@@initialState');
  const isLogin = () => {
    const isLogin = initialState?.isLogin;
    return isLogin;
  };
  useEffect(() => {
    document.title = 'The Mai'; //设置标题
  }, []);
  //是否有权限
  const hasPermission = (code: string) => {
    //functions_groups 首页展示的链接id
    if (initialState && initialState?.currentUser?.functions_groups) {
      const { functions_groups } = initialState?.currentUser;
      if (functions_groups.includes(code)) {
        return true;
      }
    }
    return false;
  };

  // const dataDoc = () => {
  //   if (isLogin()) {
  //     if (hasPermission('database')) {
  //       history.push('/dataDoc');
  //     } else {
  //       message.open({
  //         type: 'info',
  //         content: '您没有权限访问',
  //       });
  //     }
  //   } else {
  //     message.open({
  //       type: 'info',
  //       content: '您现在还未登录 请先登录！',
  //     });
  //     setTimeout(() => {
  //       history.push('/user/login?redirect=/dataDoc');
  //     }, 1000);
  //   }
  // };

  // const chatBot = (type: number) => {
  //   if (isLogin()) {
  //     history.push(`/chatBot?type=${type}`);
  //   } else {
  //     history.push(`/user/login?redirect=/chatBot?type=${type}`);
  //   }
  // };

  const conversation = () => {
    if (isLogin()) {
      if (hasPermission('article_generator')) {
        history.push('/docList');
      } else {
        message.open({
          type: 'info',
          content: '您没有权限访问',
        });
      }
    } else {
      message.open({
        type: 'info',
        content: '您现在还未登录 请先登录！',
      });
      setTimeout(() => {
        history.push('/user/login?redirect=/main');
      }, 1000);
    }
  };

  // const visitingCard = () => {
  //   if (isLogin()) {
  //     history.push('/visitingCard');
  //   } else {
  //     history.push('/user/login?redirect=/visitingCard');
  //   }
  // };

  return (
    <div className="mainWrap">
      <div className="mainHead">
        <div className="mainHead-hd">
          <AvatarDef></AvatarDef>
        </div>
      </div>
      <div className="mainBody">
        <div className="mainBody-title">
          横琴粤澳深度合作区<span className="subheading">行政事务局</span>
        </div>
        <div className="mainBody-maxTitle">写作共享实习生</div>
        <div className="title-line">
          <span></span>
        </div>
        {/* 
        <div className="mainBody-linkBox">
          <div className="mainBody-link" onClick={dataDoc}>
            去知识库
          </div>
          <div className="mainBody-link darkBg" onClick={conversation}>
            开始创作
          </div>
        </div> */}
        <div className="writingEntrance">
          <div className="mainBody-tip">
            <div className="mainBody-tip-hd">
              <img src={ROBO_AVATAR} alt="" />
            </div>
            <div className="mainBody-tip-bd">
              领导您好，我是小麦，24小时不间断写作，时刻听候您的吩咐。
            </div>
          </div>
          <div className="openWritingBox">
            <span className="openWriting-hd">开始写作吧～</span>
            <div className="openWriting-bd" onClick={conversation}>
              <img src={FASONG} alt="" />
            </div>
          </div>
        </div>
      </div>
      <div className="mainFoot">广东大麦数安科技有限公司</div>
    </div>
  );
};
export default Main;
